# Maintainer: Saul Ibarra Corretge <saghul@gmail.com>
# Contributor: Alexey Pavlov <alexpux@gmail.com>

_realname=pyqt-builder
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.6.0
pkgrel=1
pkgdesc="The PEP 517 compliant PyQt build system (mingw-w64)"
arch=('any')
license=('GPL3')
url="https://pypi.org/project/PyQt-builder/"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
source=("https://pypi.io/packages/source/P/PyQt-builder/PyQt-builder-${pkgver}.tar.gz"
        001-mingw-python.patch)
sha256sums=('fb80f01407718bfc68f78e276f2543fcfc5b5900b1187c1fd1f2ff51a6f2a13c'
            '39c21631dff9ada9bb5e7ba9c86bae9df461de2397d2cfdf53de20d04fbae548')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i "${srcdir}/001-mingw-python.patch"

  cd "${srcdir}"
  rm -rf python-build-${MINGW_CHOST} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MINGW_CHOST}"
}

build() {
  cd python-build-${MINGW_CHOST}
  
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}"/python-build-${MINGW_CHOST}
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  # Remove python.exe full path reference
  PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}/bin/||g" -i "${pkgdir}${MINGW_PREFIX}/bin/pyqt-bundle-script.py"

  install -D -m644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
